﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using AutoMapper;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TheNorthStar.Api.Requests;
using TheNorthStar.Web.Application.Mappings;
using TheNorthStar.Web.Application.Services;

namespace TheNorthStar.IntegrationTests
{
    /// <summary>
    /// Summary description for UnitTest1
    /// </summary>
    [TestClass]
    public class UnitTest1
    {
        public UnitTest1()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void WhenCreatingABooking_ShouldReturnANewBookingId()
        {
            //
            // TODO: Add test logic here
            //

            BookingMaps.Configure();
            BookingService service = new BookingService();
            NewBooking booking = new NewBooking
                                     {
                                         IMEI = "123",
                                         NumberOfPassengers = 1,
                                         PhoneNumber = "041234567",
                                         UnitNumber = 1,
                                         StreetNumber = 22,
                                         Street = "test street name",
                                         StreetType = "Avenue",
                                         Suburb = "TestSuburb"
                                     };
            var result = service.Create(booking);


            Web.Application.Mappings.BookingMaps.Configure();
            var res = Mapper.Map<Domain.Booking, Api.Results.Booking>(result);
            var jsonData = Newtonsoft.Json.JsonConvert.SerializeObject(res);

            var test = Newtonsoft.Json.JsonConvert.DeserializeObject<Api.Results.Booking>(jsonData);

            Assert.IsTrue(result.BookingId > 0);
        }

        [TestMethod]
        public void WhenUpdatingABooking_ShouldSaveTheDifferences()
        {
            BookingService service = new BookingService();
            Domain.Booking booking = new Domain.Booking();

            booking.BookingId = 21;
            booking.PickupSuburb = "Updated Suburb";
            booking.DriverId = 1;
            var res = service.Update(booking);

            var v = service.Get(21);
        }

        [TestMethod]
        public void WhenRetrievingABooking_ShouldReturnABooking()
        {
            BookingService service = new BookingService();
            
            var v = service.Get(21);

            Assert.IsNotNull(v);
        }
         [TestMethod]
        public void CheckBookingDistances()
        {


            DriverLoginService service = new DriverLoginService();
        
            //var x = service.haversine_km(-35.279486, 149.128882, -35.248164, 149.133773);
             var y = service.RequestWork(6, 0, 0);

        }
    }
}
